<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>

<div id="jobRuntimeLogToolbar">

    <input id="refresh">

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/QUARTZ/JOB_PAUSE_ALL'')')}"
       href="javascript:" class="easyui-linkbutton" iconCls="fa fa-pause" plain="true"
       onclick="jobRuntimeLogPauseOrStartRefresh();" id="jobRuntimeLogPauseOrStartRefresh">暂停/开始刷新</a>

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/QUARTZ/JOB_DELETE_ALL'')')}"
       href="javascript:" class="easyui-linkbutton" iconCls="fa fa-close" plain="true"
       onclick="jobRuntimeLogTruncate();">清空</a>

</div>

<table id="jobRuntimeLog"></table>

<script type="text/javascript">

    window._t = undefined;
    window._state = true;

    $(function () {

        $('#refresh').combobox({valueField: 'id',textField: 'text',data: [{
                id: '1000',
                text: '1000',
            },{
                id: '2000',
                text: '2000'
            },{
                id: '3000',
                text: '3000'
            },{
                id: '5000',
                text: '5000',
                selected: true
            }, {
                id: '8000',
                text: '8000'
            },{
                id: '10000',
                text: '10000'
            },{
                id: '15000',
                text: '15000'
            },{
                id: '20000',
                text: '20000'
            }
            ],

        });

        // 定时任务运行日志
        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {field: 'jobClassName', title: '任务类名'},
            {field: 'jobGroup', title: '任务分组'},
            {field: 'log', title: '日志'},
            {field: 'jobRunTime', title: '任务运行耗时（毫秒）'},
            {field: 'gmtCreated', title: '创建时间'}
        ];

        $('#jobRuntimeLog').datagrid(expressui.grid.create, {
            url: Url.Quartz.Api.JOB_RUNTIME_LOG + '/page_all',
            columns: [columns]
        });

        jobRuntimeLogStartRefresh();

    });

    function jobRuntimeLogPauseOrStartRefresh() {
        window._status = !_status;
    }

    function jobRuntimeLogStartRefresh() {
        window._t = setInterval(f, $('#refresh').combobox('getValue'));
        function f() {
            if(_status) {
                $('#jobRuntimeLog').datagrid('reload');
            }
        }
    }

    function jobRuntimeLogTruncate() {
        $('#jobRuntimeLog').datagrid(expressui.grid.post, {
            url: Url.Quartz.Api.JOB_RUNTIME_LOG + '/truncate',
            method: 'post',
            success: '操作成功',
            reload: [{type: 'datagrid', selector: '#jobRuntimeLog'}],
        });
    }

</script>
</body>
</html>